package jdbc1;

import jdbc.DBUtil;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Random;

public class Text1 {
    public static void main(String[] args) {
        try (
                Connection connection = DBUtil.getConnection();
        ){
            Statement state = connection.createStatement();
            Random r = new Random();
            for(int i=1;i<=100;i++){
                String name = "test"+i;
                int age = r.nextInt(6)+10;
                int classId = r.nextInt(10)+1;
                String sql = "INSERT INTO student1(name,age,class_id) " +
                             "VALUES('" +name + "'," +age+","+classId+")";
                System.out.println(sql);
                int count =state.executeUpdate(sql);
                if(count>0){
                    System.out.println("影响了表中"+count+"条数据");
                }
            }
            System.out.println("执行完毕");
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
